package com.xl.baseMethod;

import lombok.extern.slf4j.Slf4j;

import static java.lang.Thread.sleep;

/**
 * JdkVersion: 1.8
 * Author: lei·xie
 * Created: 2024/8/5 0002 10:22
 * Description: 实践，烧水泡茶
 */
@Slf4j(topic = "b.Test14")
public class ThreadDemo14 {
    public static void main(String[] args) throws InterruptedException{
        Thread t1 = new Thread(() -> {
            log.debug("洗水壶..");
            try {
                sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.debug("烧开水..");
            try {
                sleep(5000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        },"老王");
        t1.start();
        Thread t2 = new Thread("t2") {
            @Override
            public void run() {
                log.debug("洗茶壶..");
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                log.debug("洗茶杯..");
                try {
                    sleep(2000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                log.debug("拿茶叶..");
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                try {
                    t1.join();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                log.debug("泡茶..");
            }
        };
        t2.setName("小王");
        t2.start();
    }
}
